package com.fwmagic.dp._6._6_2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class GamePlayInvocationHandler implements InvocationHandler {

    //被代理的实例
    private Object obj ;

    //我要代理谁
    public GamePlayInvocationHandler(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(obj, args);
        //如果是登录方法，则发送消息
        if(method.getName().equalsIgnoreCase("login")){
            System.err.println("有人在用我的账户登录");
        }
        return result;
    }
}
